class UserSweeper < ActionController::Caching::Sweeper

  observe User

  # If we create a new record, the public list
  # of posts must be regenerated
  def after_create(record)
    expire_public_page
  end

  # If we update an existing record, the cached version
  # of that particular record becomes stale
  def after_update(record)
    expire_record_page(record.id)
    expire_public_page
  end

  # Deleting a page means we update the public list
  # and blow away the cached record
  def after_destroy(record)
    expire_public_page
    expire_record_page(record.id)
  end

  private

  def expire_public_page
    
  end

  def expire_record_page(record_id)
  	case record
  	when Post
  		expire_action(:controller => "browse", :action => 'index')
    	expire_action(:controller => "browse", 
                  	  :action => "post",
			  							:id     => record_id)
	when Community	  							
    	expire_action(:controller => "communities", 
                  	  :action => "show",
			  							:id     => record_id)
	end
  end

end
